<?php

/**

 * PHP自带SESSION原理处理类

 * @author andery <andery@foxmail.com>

 * @link http://www.Nimo.com/

 * @version $Id: CPHPSession.php 2010-07-23 15:41:32Z andery $

 */

class CPHPSession implements ISession{
	
	public function __construct()
	{
	    session_set_save_handler(
	        array (& $this, "_sess_open"),
            array (& $this, "_sess_close"),
            array (& $this, "_sess_read"),
            array (& $this, "_sess_write"),
            array (& $this, "_sess_destroy"),
            array (& $this, "_sess_gc")
        );
        session_start();
	}
	
    /**
     * 打开
     */
	public function sess_open()
	{
	    if (CConfig::get('session.session_expire')!='') {
	        self::setExpire(CConfig::get('session.session_expire'));
	    } else {
	        self::setExpire(1440);
	    }
	}
	
	/**
	 * 设置过期时间
	 */
	private function setExpire($time)
	{
	    $_SESSION['Session_Expire'] = time()+$time;
	}
	
	/**
	 * 关闭
	 */
	public function sess_close(){
	    session_write_close();
	}

	/**
	 * 清理过期
	 */
	public function sess_gc(){
	    
	}
	
	/**
	 * 存入
	 */
	public function sess_write(){}
	
	/**
	 * 读取
	 */
	public function sess_read(){}
	
	/**
	 * 删除
	 */
	public function sess_destroy()
	{
	    $_SESSION = array();
	}
}